const jwt = require('jsonwebtoken')
const secret = process.env.secret

module.exports = {
  /**
   * @description 生成token
   * @param {Object} data
   * @param {String} expiresIn
   * @returns token
   */
  generate(data, expiresIn) {
    return jwt.sign(data, secret, {
      expiresIn,
    })
  },
  verify(token) {
    try {
      return jwt.verify(token, secret)
    } catch (error) {
      return false
    }
  },
}
